#include "StdAfx.h"
#include "PanTool.h"
#include "GISApplication.h"
#include "canvas.h"
#include "Map2ClientTransform.h"

CPanTool::CPanTool(CGISApplication* pApplication):CTool(pApplication)
{
	m_bButtonDown = false;
}

CPanTool::~CPanTool()
{

}

void CPanTool::OnLButtonDown(CMousePoint point)
{
	m_bButtonDown = true;
	m_prePoint = point;
}

void CPanTool::OnLButtonMove(CMousePoint point)
{
	if (m_bButtonDown)
	{
		m_curPoint = point;
		CMousePoint offset(m_curPoint.m_x - m_prePoint.m_x,m_curPoint.m_y - m_prePoint.m_y);
		m_pApplication->getCanvas()->getTransform()->offset(offset);
		m_prePoint = m_curPoint;
        m_pApplication->getCanvas()->invalidate();
	}
}

void CPanTool::OnLButtonUp(CMousePoint point)
{
	if (m_bButtonDown)
	{
        m_pApplication->getCanvas()->invalidate();
        m_bButtonDown = false;
	}    
}

void CPanTool::OnMouseWheel(CMousePoint point, double delta)
{
	double scaleFactor;
	if (delta > 0)
	{
		scaleFactor = delta/120*0.8;
	}
	else
	{
		scaleFactor = delta/-120/0.8;
	}
	//	
	//m_pApplication->getCanvas()->getTransform()->zoom(delta);
	m_pApplication->getCanvas()->getTransform()->zoomAtPoint(point,scaleFactor);
	m_pApplication->getCanvas()->invalidate();
}
